<template>
  <div class="wraps">
    <div class="title">
      <img src="../../images/main/par.png" alt>
      <span class="back" @click="backParMan()">活动详情</span>
      &nbsp;&nbsp;<el-button type="primary" @click="goBack">返回</el-button>
    </div>
    <div class="clear"></div>
    <div class="nowParman" v-if="acDetails.states == 1">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待合作</span>
      <div class="info">当前活动订单等待合作双方确认分成比例。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 2">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待审核</span>
      <div class="info">通过审核后，该活动可进行报名。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 3">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已驳回</span>
      <div class="info">当前订单被驳回，驳回原因：{{acDetails.reject}}</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 4">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待报名</span>
      <div class="info">活动订单已生成，若在活动开始前24小时未达到活动最低成团人数，系统将自动取消订单。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 5">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已成团 </span>
      <div class="info">当前报名人数已经成团，请等待活动开始。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 6">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >待签到</span>
      <div class="info">通过审核后，该活动可进行报名。</div>
    </div>
    <div class="nowParman" v-else-if="acDetails.states == 7">
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已结束</span>
      <div class="info">当前活动已圆满结束，结算后您可以通过财务进行提现操作。</div>
    </div>
    <div class="nowParman" v-else>
      <span class="peopleType">当前合伙人：</span>
      <span class="nows" >已关闭</span>
      <div class="info">当前活动已超过报名时间，报名人数未达到最低成团邀请，活动已被系统关闭。</div>
    </div>
    <div class="mans">
      <span>活动信息</span>
    </div>
    <div class="body">
      <div class="list">
        <ul class="listBody">
          <li>
            <span class="listTitle">服务商：</span>
            <span class="listValue" :title="acDetails.serviceName">{{acDetails.serviceName}}</span>
          </li>
          <li>
            <span class="listTime">门店名称：</span>
            <span class="listValue" :title="acDetails.storeName">{{acDetails.storeName}}</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">订单编号：</span>
            <span class="listValue">{{acDetails.activityNo}}</span>
          </li>
          <li>
            <span class="listTime">订单时间：</span>
            <span class="listValue">{{setDate(acDetails.releaseTime)+' '+setTime(acDetails.releaseTime)}}</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动开始时间：</span>
            <span class="listValue">{{setDate(acDetails.activityTime)+' '+setTime(acDetails.activityTime)}}</span>
          </li>
          <li>
            <span class="listTime">活动结束时间：</span>
            <span class="listValue">{{setDate(acDetails.endTime)+' '+setTime(acDetails.endTime)}}</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动可参与人数：</span>
            <span class="listValue">{{acDetails.participateMin}}-{{acDetails.participateMax}}人</span>
          </li>
          <li>
            <span class="listTime">当前报名人数：</span>
            <span class="listValue">{{acDetails.signCount}}人 ({{Number(acDetails.participateMin) > Number(acDetails.signCount) ? '还差'+ Number(acDetails.participateMin - acDetails.signCount) + '人成团' : '已成团' }})</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">客户报名费：</span>
            <span class="listValue">{{acDetails.activityPrice.toFixed(2)}}元/人</span>
          </li>
          <li>
            <span class="listTime">活动分成：</span>
            <span class="listValue">服务商{{acDetails.percentage}}% : 门店{{ 100 - acDetails.percentage}}%</span>
          </li>
        </ul>
        <div class="clear"></div>
        <ul class="listBody">
          <li>
            <span class="listTitle">活动地址：</span>
            <span class="listValue address" :title="acDetails.activityAddress">{{acDetails.activityAddress}}</span>
          </li>
          
          <li>
            <span class="listTime">报名截止时间：</span>
            <span class="listValue">{{setDate(acDetails.closingTime)+' '+setTime(acDetails.closingTime)}}</span>
          </li>
        </ul>
        <div class="clear"></div>

        <ul class="listBody">
          <li>
            <span class="listTitle">场地类型：</span>
            <span class="listValue">{{acDetails.roomType}}</span>
          </li>
          <li>
            <span class="listTime">适用年龄：</span>
            <span class="listValue">{{acDetails.age + '岁' || '-'}}</span>
          </li>
        </ul>
        <div class=""></div>
      </div>
    </div>
    <div class="examine" v-if="acDetails.states == 2">
      <div @click="adopt" style="cursor: pointer;">通过审核</div>
      <div @click="reject" style="cursor: pointer;">驳回</div>
    </div>
      <div class="table" v-if=" acDetails.states == 4 || acDetails.states == 5 || acDetails.states == 6 || acDetails.states == 7 || acDetails.states == 8">
        <div class="sthead">
          <div>头像</div>
          <div>微信昵称</div>
          <div>手机号</div>
          <div>报名费(元)</div>
          <div>交易单号</div>
          <div class="update">报名时间</div>
          <div>状态</div>
          <div>操作</div>
        </div>
        <div class="tlists">
          <div v-if="userList.length == 0" style="height:40px;line-height:40px;text-align:center;border:1px solid #ccc;"> 暂无数据</div>
          <div
           v-else 
            class="tlist"
            
            v-for="( item, index ) in userList"
            >
            <div >
              <img
                class="tlogo"
                :src="item.user_img"
              />
            </div>
            <div>{{ item.nick_name }}</div>
            <div>{{ item.user_phone }}</div>
            <div>{{ item.pay_price.toFixed(2) }}</div>
            <div>{{ item.order_num }}</div>
            <div class="update">
              <div>{{setDate(item.pay_time)}} </div>
              <div>{{setTime(item.pay_time)}}</div>
            </div>
            <div>{{ item.qian ? '已签到' : '未签到' }}</div>
             <div
          v-if="(item.states == 7) && roleList.search('退款') != '-1' && item.pay_states == 1"
          @click="refund( item.id )"
          >
          退款
        </div>
        <div
          v-if="(item.states == 7) && roleList.search('退款') != '-1' && item.pay_states == 2"
          >
          已退款
        </div>
          </div>
         
        </div>
        <div :style="{textAlign: 'center', padding: '50px 0'}">
          <el-button
            type="success" v-if="acDetails.jingXuan == 0"
            @click="recommendation( 1 )"
            >
            推荐精选
          </el-button>
          <el-button v-else
            type="danger"
            @click="recommendation( 0 )"
            >
            取消精选
          </el-button>
          <el-button
            type="warning"
            @click="setTags"
            >
            设置标签
          </el-button>
        </div>
      </div>
      <div class="task" v-if="task">
      <div class="bgc">
        <div class="box_tip">
          <div class="tips">设置标签</div>
          <div class="btn_x">
            <a class="x"
              @click="closeTag()">×</a>
          </div>
          <hr>
          <div class="tagbody" >
            <div  v-for="(items,index) in tagList" :class="(tagId == items.id) ? 'ctag tags' : 'tags'"  :key="index" @click="changeTags(items.id)">{{items.name}}</div>
          </div>
          <div class="btn_submit"
            type="submit"
            @click="saveTags()">提交</div>

        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Global from '../tool/Global.vue'
import axios from 'axios'
import qs from 'qs' // 将请求转换成form 表单提交形式
export default {
  created () {
    this.getUserList();
  },
  data() {
    return {
      acDetails: {},
      userList: [],
      tagId: '',
      task: '',
      tagList: [],
    };
  },
  methods: {
    goBack(){
      this.$router.push({
        path:'/main/activity',
        query:{ActivityNum:1}
      })
    },
     /*
      * 退款
       */
       refund: function (id) {
         let that = this;
         this.$prompt('退款原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
         }).then( ({value}) => {
           axios({
          method: 'post',
          url:`${that.$store.state.url}/tActivity/tui`,
            data:qs.stringify({
              signId:id,
              reason: value
            })
      }).then(res => {
            if(res.data.code == 0) {
              this.$alert('退款成功!')
            } else {
              this.$alert(res.data.msg)
            }
        });
         })
      
       },
    // 设置精选
    recommendation( jing_xuan ) {
        this.loading = true;
        axios.post (
          `${this.$store.state.url}/tActivity/updateJingXuan`,
          qs.stringify ({
              id: this.$route.query.id,
              jing: jing_xuan
          })
        ).then ( response => {
          this.loading = false;
          let res = response.data;
          if ( res.code == 0 ) {
            this.$alert ( '设置成功' );
            this.getAcDetail()
          }
        }, () => {
          this.loading = false;
        });
      },
    // 通过
    adopt() {
      let id = this.$route.query.id;
      this.loading = true;
      axios.post (
        `${this.$store.state.url}/tActivity/updateStates`,
        qs.stringify ({
          id: id,
          states: 4
        })
      ).then ( response => {
        this.loading = false;
        let res = response.data;
        if ( res.code == 0 ) {
          this.$alert ( '审核已通过' ).then ( response => {
            this.$router.back ( -1 );
          });
          // this.getAcList();
        }
      }, () => {
        this.loading = false;
      });
    },
    // 驳回
    reject() {
      let id = this.$route.query.id;
      this.$prompt ( '驳回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        this.loading = true;;
        axios.post (
          `${this.$store.state.url}/tActivity/rejectActivity`,
          qs.stringify ({
            id: id,
            reject: value
          })
        ).then ( response => {
          this.loading = false;
          let res = response.data;
          if ( res.code == 0 ) {
            this.$alert ( '驳回成功' ).then ( response => {
              this.$router.back ( -1 );
            });
          }
        }, () => {
          this.loading = false;
        });
      }).catch(() => {

      });
    },

    backParMan: function() {
      this.$router.push({
        path: "/main",
        name: "parMan"
      });
    },
    getAcDetail: function () {
      // let id = Global.activityId
      let id = this.$route.query.id;
      let that = this
      axios({
          method: 'post',
          url:`${that.$store.state.url}/tActivity/selectDateils`,
            data:qs.stringify({id:id})
      }).then(res => {
            console.log(res)
          if (res.data.code == 0) {
            that.acDetails = res.data.data
          } else {
            this.$alert(res.msg);
          }
        });
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function (str) {
        let times = new Date(str)
        return `${times.getFullYear()}-${times.getMonth()+1 < 10 ? '0' + (times.getMonth()+1):times.getMonth()+1}-${times.getDate() < 10 ? '0' + times.getDate() : times.getDate()}`
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function (str) {
        let times = new Date(str)
        return `${times.getHours() < 10 ? '0' + times.getHours() : times.getHours()}:${times.getMinutes() < 10 ? '0' + times.getMinutes() : times.getMinutes()}:${times.getSeconds() < 10 ? '0' + times.getSeconds() : times.getSeconds()}`
    },

    // 获取用户列表
    getUserList() {
      axios.post (
        `${this.$store.state.url}/tActivity/selectSignList`,
        qs.stringify ({
          activityId: this.$route.query.id
        })
      ).then ( response => {
        let res = response.data;
        if ( res.code == 0 ) {
          this.userList = res.data;
        }
      })
    },


      /**
     * 关闭标签修改
     */
    closeTag: function() {
      this.task = false;
    },
      /**
       * 保存标签
       */
      saveTags: function () {
        axios.post (
          `${this.$store.state.url}/tActivity/addLable`,
          qs.stringify ({
              id: this.$route.query.id,
              lableId:this.tagId

          })
        ).then ( response => {
          let res = response.data;
          if ( res.code == 0 ) {
           this.$alert ( '设置成功' );
           this.task = false;
          }
        })
      },
      /**
       * 设置标签
       */
      changeTags: function (id) {

        this.tagId = id
        console.log(this.tagId)
      },
      /*
      * 获取活动标签列表 tLabel/selectLista
      */
      getTagList: function () {
        axios.post (
          `${this.$store.state.url}/tLabel/selectList`,
        ).then ( response => {
          let res = response.data;
          if ( res.code == 0 ) {
           this.tagList = res.data
           this.geTagChange()
          }
        })
      },
      setTags( id ) {
        this.task = true
        this.activeId = id
        this.getTagList()

      },
      geTagChange: function () {
        axios.post (
          `${this.$store.state.url}/tActivity/selectLabelByActivityId`,
          qs.stringify ({
            id: this.$route.query.id
          })
        ).then ( response => {
          let res = response.data;
          if ( res.code == 0 ) {
            this.tagId = res.data.id
          }
        })
      },
  },
  mounted () {
    this.getAcDetail()
  }
};
</script>
<style scoped>
.wraps {
  padding: 68px 136px;
  background: rgb(236, 238, 243);
}
.address {
  display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
.nowParman {
  margin-top: 37px;
  margin-left: 48px;
}
.nowParman span {
  font-size: 18px;
  font-weight: bold;
}
.nows {
  color: #d81e06;
}
.info {
  margin-top: 19px;
  margin-bottom: 35px;
  height: 20px;
  line-height: 20px;
  font-size:14px;
  color:#4a4a4a;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title span {
  float: left;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.title .right {
  width: 11px;
  height: 18px;
  padding-top: 9px;
  margin-left: 5px;
  margin-right: 6px;
}
.body {
  background: white;
  border: 1px solid #dddddd;
  /* width: 1492px; */
  height: 415px;
  margin-top: -1px;
  margin-left: 45px;
  /* padding-left: 139px; */
  padding-top: 63px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.mans {
  background: #e0eefe;
  border: 1px solid #dddddd;
  /* width: 1490px; */
  height: 67px;
  margin-left: 45px;
}
.mans span {
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  letter-spacing: 0.02px;
  text-align: left;
  font-weight: bold;
  line-height: 70px;
  margin-left: 39px;
  display: inline-block;
  width: 74px;
  text-align: right;
}
.listBody {
  /* width: 1376px; */
  /* display: inline-block; */
  width: 85%;
  margin: 0 auto;
}
.listValue {
  margin-left: 25px;
  /* width: 516px; */
  /* display: inline-block; */
  float: left;
  display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
width: 55%;
line-height: 20px;
}
.listBody li {
  float: left;
  width: 50%;
}
.listBody li span {
  float: left;
}
.listBody li .listTitle {
  display: inline-block;
  width: 146px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #727272;
  letter-spacing: 0.02px;
  text-align: right;
  font-weight: bold;
}
.listTime {
  display: inline-block;
  width: 128px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #727272;
  letter-spacing: 0.02px;
  text-align: right;
  font-weight: bold;
}
.listValue {
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  letter-spacing: 0.02px;
  text-align: left;
  font-weight: bold;
      /* max-width: 209px; */
    overflow: hidden;
    height: 18px;
}
.list .clear {
  height: 33px;
}
.endDetail {
  position: relative;
}
.imgsBuy {
  background: white;
  box-shadow: 0 1px 5px 0 #b8b7b9;
  width: 320px;
  height: 205px;
  position: absolute;
  left: 170px;
}
.wrap {
  padding: 68px 136px;
  width: 100%;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.screen {
  height: 60px;
  background: #f6f6f6;
  margin-left: 38px;
  margin-top: 24px;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  margin-top: 27px;
  padding-left: 38px;
  height: 40px;
  line-height: 40px;
}
.sel .txt {
  float: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
  width: 73px;
}
.sel input {
  float: left;
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 40px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
}
.btn {
  float: left;
  color: #fff;
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  text-align: center;
  margin-left: 37px;
}
.table {
  margin-top: 43px;
  margin-left: 45px;
}
.table .sthead {
  border-bottom: 1px solid #dddddd;
  height: 67px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  line-height: 67px;
  font-weight: bold;
  background: #e0eefe;
  display: flex;
}
.parname {
  width: 187px;
}
.parname img {
  margin: 18px 0 0 9px;
  width: 170px;
  height: 90px;
  float: left;
}
.sthead > div {
  float: left;
  text-align: center;
  box-sizing: border-box;
  flex: 1;
}
.parnum {
  width: 149px;
}
.phone {
  width: 162px;
}
.area {
  width: 137px;
}
.monkey {
  width: 147px;
}
.date {
  width: 140px;
}
.update {
  width: 184px;
}
.state {
  width: 142px;
}
.table .thead {
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 24px;
  color: #000000;
  height: 69px;
  line-height: 69px;
  padding-left: 15px;
  background: #e0eefe;
  border: 1px solid #dddddd;
  box-sizing: border-box;
  font-weight: bold;
}
.addpar {
  background: #f6f6f6;
  border: 1px solid #085dab;
  border-radius: 2px;
  width: 107px;
  height: 33px;
  float: right;
  font-family: PingFangSC-Regular;
  font-size: 14px;
  line-height: 33px;
  margin-top: 17px;
  margin-right: 20px;
  color: #085dab;
  cursor: pointer;
}
.add {
  width: 18px;
  height: 18px;
  float: left;
  margin: 8px;
}
.tlist > div {
  height: 142px;
  flex: 1;
}
.tlist .update {
  line-height: 25px;
  /* padding-top: 43px; */
  height: 142px;
}
.day,
.time {
  height: 25px;
  line-height: 25px;
}
.ctrl {
  width: 242px;
}
.tlist {
  height: 142px;
  line-height: 142px;
  /* width: 1490px; */
  display: flex;
}
.lastlist {
  border-right: 1px solid #ddd;
}
.tlist > div {
  float: left;
  text-align: center;
  box-sizing: border-box;
  flex-direction: column;
  justify-content: center;
  white-space:normal; word-break:break-all;
  line-height: 20px;
      display: flex;
}
.tlist:last-of-type {
  background: white;
  border-bottom: 1px solid #ddd;
}
.ctrl ul {
  width: 179px;
  padding: 18px 19px 20px 31px;
  height: 104px;
}
.ctrl ul li {
  float: left;
  width: 72px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #085dab;
  margin-top: 15px;
  font-weight: bold;
  cursor: pointer;
}
.ctrl ul li:nth-of-type(2n) {
  margin-left: 35px;
}
.ctrl .firli {
  margin-top: 0px;
}
.clear {
  clear: both;
}
.examine {
  height: 54px;
  line-height: 54px;
  text-align: center;
  margin-top: 66px;
}
.examine > div {
  width: 254px;
  height: 54px;
  text-align: center;
  line-height: 54px;
  margin-left: 66px;
  font-size:18px;
  color:#ffffff;
  font-weight: bold;
  display: inline-block;
  background:#085dab;
}
.examine :first-child {
  margin-left: 0;
}








.box_tip {
  background: #ffffff;
  box-shadow: 0 2px 9px 0 rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  width: 646px;
  height: 399px;
  text-align: center;
  padding-top: 21px;
  overflow: hidden;
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
  z-index: 2000;
}
.tips {
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  font-weight: bold;
  height: 35px;
  line-height: 35px;
}
.btn_x {
  background: #9b9b9b;
  width: 86px;
  height: 86px;
  border-radius: 100%;
  position: absolute;
  right: -43px;
  top: -43px;
}
.x {
  font-size: 25px;
  text-decoration: none;
  position: absolute;
  left: 19px;
  bottom: 15px;
  color: #fff;
  font-weight: bold;
}
hr {
  opacity: 0.38;
  background-color: #979797;
  width: 306px;
  height: 2px;
  margin-top: 8px;
}
.text_input {
  margin-top: 103px;
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 311px;
  height: 40px;
  text-align: center;
  font-size: 18px;
  color: #4a4a4a;
}
.btn_submit {
  display: block;
  margin:20px auto;
  background: #085dab;
  width: 200px;
  height: 45px;
  line-height: 45px;
  padding: 0px;
  margin-bottom: 0px;
  cursor: pointer;
  color: #ffffff;
}

.tagbody {
  height: 240px;
}
.tags {
  background:#ffffff;
border:1px solid #ddd;
border-radius:2px;
min-width:68px;
height:28px;
display: inline-block;
margin: 20px ;
line-height: 28px;
}
.ctag {
  border:1px solid #085dab;
}
.box_tip {
  background: #ffffff;
  box-shadow: 0 2px 9px 0 rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  width: 646px;
  height: 399px;
  text-align: center;
  padding-top: 21px;
  overflow: hidden;
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
  z-index: 2000;
}
</style>
